home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8330 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: more problems with qsort
  5. Date: 3 Mar 1996 00:29:13 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4hbe7p$reg@solutions.solon.com>
  8. References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net> <4h81m0$avr@solutions.solon.com> <4hba5n$2ga@clarknet.clark.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4hba5n$2ga@clarknet.clark.net>, yom <yom@clark.net> wrote:
  12. >In article <4h81m0$avr@solutions.solon.com>, seebs@solutions.solon.com 
  13. >says...
  14. >>>And your compare function must be defined like this:
  15.  
  16. >>>int compare(char **a,char **b) {return strcmp(*a,*b);}
  17.  
  18. >>No, it really mustn't.  It must be defined like this:
  19. >>int compare(const void *a, const void *b) {
  20. >>        return strcmp(*(char **) a, *(char **) b);
  21. >>}
  22.  
  23. >Well I disagree on this one.
  24.  
  25. Then you are wrong.
  26.  
  27. Calling conventions for functions may vary by type of arguments; the
  28. qsort() function will pass pointers into the compare function as
  29. (void *).  If the cast is nontrivial, which it may be on some systems,
  30. then if the function does not cast the arguments, it looses.
  31.  
  32. >Also, I tend to not use "const" because some compilers do
  33. >not support it.
  34.  
  35. But a compiler may legitimately reject the code for incompatabilities
  36. if you omit the const.
  37.  
  38. -s
  39. -- 
  40. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  41. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  42. FUCK the communications decency act.  Goddamned government.  [literally.]
  43. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  44.